layui.use(['func', 'laydate', 'upload'], function () {

    //声明变量
    var func = layui.func
        , $ = layui.$
        , laydate = layui.laydate
        , upload = layui.upload;

    if (A === "index") {
        let cols = [
            {width: 80, title: 'ID', align: "center", templet: d => d.LAY_INDEX}
            , {field: 'id', width: 80, title: 'ID', hide: true, align: 'center', sort: true}
            , {field: 'name', width: 100, title: '名称', align: "center"}
            , {
                field: 'image', width: 150, title: '图片', align: "center", templet: function (d) {
                    var imageStr = "";
                    if (d.image) {
                        imageStr = '<a href="' + d.image + '" target="_blank"><img src="' + d.image + '" height="26" /></a>';
                    }
                    return imageStr;
                }
            }
            , {field: 'address', title: '地址', align: "center"}
            , {field: 'description', title: '描述', align: "center"}
            , {field: 'price', width: 80, title: '价格/天', align: "center"}
            , {field: 'period', width: 180, title: '可租赁时间段', align: "center"}
            , {fixed: 'right', width: 150, title: '功能操作', align: 'center', toolbar: '#toolBar'}
        ];

        //【渲染TABLE】
        func.tableIns(cols, "tableList");

        //【设置弹框】
        func.setWin("摊位");
    } else if(A === "edit") {
        laydate.render({
            elem: '#period',
            range: '~',
            min: 0,
            max: 7,
            // value: $("input[name=period]").data("period")
        });
        upload.render({
            elem: "#upload",
            url: '/api/upload',
            done: function (res, index, upload) {
                let item = this.item;
                $("#image_preview").attr("src", res.path);
                $("input[name=image]").val(res.path);
            }
        })
    }
});